package com.neusoft.productsys.controller;

import com.neusoft.productsys.entity.Product;
import com.neusoft.productsys.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@WebServlet("/showp.do")
public class ProductServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ProductService service = new ProductService();
        String method = req.getParameter("method");
        if(null!=method&&method.equals("queryID")){
            String id = req.getParameter("pid");
            Product product= service.queryOneByID(Integer.parseInt(id));
            req.setAttribute("product",product);
            req.getRequestDispatcher("view/product/modify_product.jsp").forward(req,resp);
        }else {
            ///TODO 应该调用service 返回一个商品的集合
            req.setAttribute("plist", service.queryAll());//将查询回来的数据存放进request
            req.getRequestDispatcher("view/product/showList.jsp").forward(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doPost(req, resp);
        doGet(req,resp);
    }
}
